package com.mmall.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.mmall.beans.PageQuery;
import com.mmall.beans.PageResult;
import com.mmall.common.JsonData;
import com.mmall.model.SysUser;
import com.mmall.param.UserParam;
import com.mmall.service.SysRoleService;
import com.mmall.service.SysTreeService;
import com.mmall.service.SysUserService;

@Controller
@RequestMapping("/sys/user")
public class SysUserController {
	
	@Resource
    private SysUserService sysUserService;
    @Resource
    private SysTreeService sysTreeService;
    @Resource
    private SysRoleService sysRoleService;
	
	@RequestMapping("/noAuth.page")
    public ModelAndView noAuth() {
        return new ModelAndView("noAuth");
    }
	
	@RequestMapping("/user.page")
    public ModelAndView page() {
        return new ModelAndView("/sys/user/userList");
    }
	
	@RequestMapping("/page.json")
	@ResponseBody
	public JsonData queryList(@RequestParam("deptId") String deptId,PageQuery pageQuery){
		PageResult<SysUser> result = sysUserService.getPageByDeptId(deptId, pageQuery);
        return JsonData.success(result);
	}
	
	@RequestMapping("/save.page")
    public ModelAndView saveUserPage() {
        return new ModelAndView("/sys/user/userAdd");
    }
	
	@RequestMapping("/save.json")
	@ResponseBody
	public JsonData saveUser(UserParam param){
		sysUserService.save(param);
		return JsonData.success(null,"新增用户信息成功");
	}
	
	@RequestMapping("/edit.page")
    public ModelAndView editUserPage() {
        return new ModelAndView("/sys/user/userEdit");
    }
	
	@RequestMapping("/update.json")
	@ResponseBody
	public JsonData updateUser(UserParam param){
		sysUserService.update(param);
		return JsonData.success(null,"修改客户信息成功");
	}
	
	@RequestMapping("/delete.json")
	@ResponseBody
	public JsonData deleteUser(@RequestParam("id") String userId){
		sysUserService.delete(userId);
		return JsonData.success(null,"删除用户信息成功");
	}

}
